Skip to content

Add gradient alpha interpolation option and Fill(Pen) - #436

Merged
JimBobSquarePants merged 2 commits into
mainfrom
js/gradient-alpha-and-pen-fill
Nov 27, 2026
Merged

JimBobSquarePants merged 2 commits into
mainfrom
js/gradient-alpha-and-pen-fill

Conversation

@JimBobSquarePants

Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Gradient alpha interpolation

  • GradientBrush (linear, radial, elliptic, sweep) and PathGradientBrush get a new PixelAlphaRepresentation AlphaRepresentation property and new constructor overloads.
  • Associated is the default. It interpolates premultiplied colors, as CSS Color 4 requires. The existing output does not change.
  • All other values interpolate unassociated colors, as SVG 2 requires. A gradient from opaque red to transparent blue then shows purple between the two stops.
  • The CPU and WebGPU backends both obey the property. Transform, Equals and GetHashCode include it.

DrawingCanvas.Fill(Pen, ...)

  • New Fill(Pen, IPath), with Rectangle, IPathCollection and PathBuilder overloads.
  • It fills the stroke that Pen.GeneratePath returns with the brush of the pen. The stroke always uses the non-zero fill rule.
  • The drawing transform changes the stroke as it changes all filled shapes, so a non-uniform scale or a skew changes the stroke width. Draw(Pen, ...) keeps an even stroke width.

ImageSharp 5

  • Update SixLabors.ImageSharp to 5.0.0-alpha.0.38, and fix the API changes.
  • The gradient encoders, the WebGPU ramp and solid color specialization, and the acrylic tint now use the ImageSharp 5 pixel alpha APIs, not hand-written premultiply code.
  • The configuration tests expect the 15 default formats of ImageSharp 5. The HalfSingle path gradient test uses values in the [0, 1] range, because ImageSharp 5 keeps HalfSingle values as HDR values.

Layer effect tint

  • The CPU acrylic, drop shadow, backdrop drop shadow, glow and inner shadow effects converted the tint color to Rgba32 before they built the color matrix. That cut the tint to 8 bits for each channel.
  • The CPU effects now use the full-precision color, the same as the WebGPU effects.

Tests

  • The gradient tests check the midpoint value of each brush kind against the CSS and SVG rules, and check that Transform keeps the alpha representation.
  • The WebGPU tests compare the CPU and WebGPU output for all brush kinds in both representations, and for Fill(Pen, ...) under a non-uniform scale.
  • A canvas test checks that Fill(Pen, ...) uses the non-zero rule under an even-odd state.

- Update SixLabors.ImageSharp to 5.0.0-alpha.0.38 and fix the API breaks.
- Add AlphaRepresentation to GradientBrush and PathGradientBrush.
  Associated (the default) interpolates premultiplied colors, as CSS
  Color 4 requires. All other values interpolate unassociated colors,
  as SVG 2 requires. Both the CPU and the WebGPU backends obey it.
- Use the ImageSharp 5 pixel alpha APIs in the gradient encoders, the
  WebGPU ramp and solid color specialization, and the acrylic tint.
- Add DrawingCanvas.Fill(Pen, ...). It fills the stroke of the path
  with the brush of the pen and the non-zero rule. The drawing
  transform changes the stroke as it changes all filled shapes.
- Update the tests for ImageSharp 5: 15 default formats, and HalfSingle
  values in the HDR range.
The CPU acrylic, drop shadow, backdrop drop shadow, glow and inner
shadow effects converted the tint color to Rgba32 before they built
the color matrix. That cut the tint to 8 bits for each channel, while
the WebGPU effects use the full-precision color. The CPU effects now
use Color.ToScaledVector4 with the same alpha representation as their
WebGPU counterparts.
@JimBobSquarePants JimBobSquarePants added this to the v4.0.0 milestone Nov 27, 2026
@JimBobSquarePants JimBobSquarePants added bug Something isn't working enhancement New feature or request area:drawing API dependencies Pull requests that update a dependency file area:gpu labels Nov 27, 2026
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.81013% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 80%. Comparing base (6f792ac) to head (2ccdbe2).

Files with missing lines Patch % Lines
...ageSharp.Drawing/Processing/RadialGradientBrush.cs 52% 9 Missing ⚠️
...geSharp.Drawing/Processing/DrawingCanvas.Shapes.cs 0% 8 Missing ⚠️
src/ImageSharp.Drawing/Processing/GradientBrush.cs 69% 4 Missing ⚠️
...ImageSharp.Drawing/Processing/PathGradientBrush.cs 91% 2 Missing ⚠️
...awing/Processing/Backends/DefaultDrawingBackend.cs 50% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #436   +/-   ##
=====================================
  Coverage     80%     80%           
=====================================
  Files        439     439           
  Lines      49890   49960   +70     
  Branches    5892    5891    -1     
=====================================
+ Hits       40297   40390   +93     
+ Misses      7998    7972   -26     
- Partials    1595    1598    +3     
Flag Coverage Δ
unittests 80% <84%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JimBobSquarePants
JimBobSquarePants merged commit a4e94b8 into main Nov 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API area:drawing area:gpu bug Something isn't working dependencies Pull requests that update a dependency file enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant